import { ipcMain, IpcMain, app } from 'electron/main'
import windowUtil from './window-util'

export function setMainListener(fns: ((ipcMain: IpcMain) => void)[]): void {
  fns.forEach((fn) => {
    fn(ipcMain)
  })
}

export const checkSecondInstance = (): void => {
  const lock = app.requestSingleInstanceLock()
  if (!lock) {
    app.quit()
  } else {
    app.on('second-instance', () => {
      if (windowUtil.wins['main']?.isMinimized()) {
        windowUtil.wins['main']?.restore()
      }
    })
  }
}
